package com.ruoyi.bussiness.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bussiness.domain.AdAdvertising;
import com.ruoyi.bussiness.service.IAdAdvertisingService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 广告信息Controller
 * 
 * @author ruoyi
 * @date 2023-11-12
 */
@Controller
@RequestMapping("/bussiness/advertising")
public class AdAdvertisingController extends BaseController
{
    private String prefix = "bussiness/advertising";

    @Autowired
    private IAdAdvertisingService adAdvertisingService;

    @RequiresPermissions("bussiness:advertising:view")
    @GetMapping()
    public String advertising()
    {
        return prefix + "/advertising";
    }

    /**
     * 查询广告信息列表
     */
    @RequiresPermissions("bussiness:advertising:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AdAdvertising adAdvertising)
    {
        startPage();
        List<AdAdvertising> list = adAdvertisingService.selectAdAdvertisingList(adAdvertising);
        return getDataTable(list);
    }

    /**
     * 导出广告信息列表
     */
    @RequiresPermissions("bussiness:advertising:export")
    @Log(title = "广告信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AdAdvertising adAdvertising)
    {
        List<AdAdvertising> list = adAdvertisingService.selectAdAdvertisingList(adAdvertising);
        ExcelUtil<AdAdvertising> util = new ExcelUtil<AdAdvertising>(AdAdvertising.class);
        return util.exportExcel(list, "广告信息数据");
    }

    /**
     * 新增广告信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存广告信息
     */
    @RequiresPermissions("bussiness:advertising:add")
    @Log(title = "广告信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AdAdvertising adAdvertising)
    {
        return toAjax(adAdvertisingService.insertAdAdvertising(adAdvertising));
    }

    /**
     * 修改广告信息
     */
    @RequiresPermissions("bussiness:advertising:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AdAdvertising adAdvertising = adAdvertisingService.selectAdAdvertisingById(id);
        mmap.put("adAdvertising", adAdvertising);
        return prefix + "/edit";
    }

    /**
     * 修改保存广告信息
     */
    @RequiresPermissions("bussiness:advertising:edit")
    @Log(title = "广告信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AdAdvertising adAdvertising)
    {
        return toAjax(adAdvertisingService.updateAdAdvertising(adAdvertising));
    }

    /**
     * 删除广告信息
     */
    @RequiresPermissions("bussiness:advertising:remove")
    @Log(title = "广告信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(adAdvertisingService.deleteAdAdvertisingByIds(ids));
    }
}
